package com.ninth_group.dao.Impl;

import com.ninth_group.dao.PCWeatherInfoDao;
import com.ninth_group.po.PCWeatherInfo;
import com.ninth_group.utils.HiveUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.List;

@Repository
public class PCWeatherInfoDaoImpl implements PCWeatherInfoDao {
    @Autowired
    private HiveUtil hiveUtil;

    private static final String QUERY_SQL = "SELECT * FROM provincial_capital_weather_info";
    /**
     * 获取所有省会天气信息
     * @return List<PCWeatherInfo>
     */
    @Override
    public List<PCWeatherInfo> getPCWeatherInfo() {
        return  hiveUtil.executeQuery(QUERY_SQL, (rs) -> {
            try {
                return PCWeatherInfo.mapRow(rs);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        });
    }
}
